
using AnesSystem.Models;


using AnesSystem.ViewModels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// PaiTai_ShouShuJian.xaml 的交互逻辑
    /// </summary>
    public partial class PaiTai_ShouShuJianCtrl : UserControl
    {

        #region Variables

        

        #endregion

        #region Constructor
        public PaiTai_ShouShuJianCtrl()
        {
            InitializeComponent();
        }


        #endregion

        #region Properties


        #endregion

        #region Event

        #endregion

        #region Private Methods

        private void SetRoomSelectedStyle()
        {

            List<ToggleButton> btnList = Common.UIHelper.FindVisualChild<ToggleButton>(_listBox);
            foreach (var item in btnList)
            {
                ConfigRoomAndTaiShu obj = item.DataContext as ConfigRoomAndTaiShu;
                if (obj.ConfigOperationRoomModel.Name.Equals(SecheduleMainCtrlViewModel.Instance.CurrentRoom.ConfigOperationRoomModel.Name))
                {
                    item.IsChecked = true;
                }
                else
                {
                    item.IsChecked = false;
                }
            }
        }


        #endregion

        #region Public/Protected Methods

        #endregion

        #region EventHandlers

        private void room_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SecheduleMainCtrlViewModel.Instance.CurrentRoom = (sender as ToggleButton).DataContext as ConfigRoomAndTaiShu;
                SetRoomSelectedStyle();
                SecheduledListCtrlViewModel.Instance.Refresh();
            }
            catch (Exception ex)
            {
                Common.LogHelper.Error("PaiTai_ShouShuJianCtrl", ex);

            }
        }

        private void room_Drop(object sender, DragEventArgs e)
        {
            IList list = null;
            //拖动对象类型 1 未排班 2 已排班
            int type = 0;
            if (e.Data.GetData("1") != null)
            {
                list = e.Data.GetData("1") as IList;
                type = 1;
            }
            else if (e.Data.GetData("2") != null)
            {
                list = e.Data.GetData("2") as IList;
                type = 2;
            }
            Button btn = (sender as Button);
            ConfigRoomAndTaiShu room = btn.DataContext as ConfigRoomAndTaiShu;
            if (SecheduleMainCtrlViewModel.Instance.CurrentRoom == null ||
                type == 1 ||
                (type == 2 && list != null && room.ConfigOperationRoomModel.Id != SecheduleMainCtrlViewModel.Instance.CurrentRoom.ConfigOperationRoomModel.Id))
            {
                SecheduleMainCtrlViewModel.Instance.CurrentRoom = room;
                SetRoomSelectedStyle();
                SecheduleMainCtrlViewModel.Instance.AddSecheduled(list);
                SecheduleMainCtrlViewModel.Instance.RefUI();
            }
        }

        private void room_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetData("1") != null || e.Data.GetData("2") != null)
            {
                e.Effects = DragDropEffects.Copy;
                e.Handled = true;
            }
        }

        #endregion

        #region Command

        #region ChangeDoctorCommand


        #endregion

        #region OpenPopupCommand

        #endregion

        #endregion


    }
}
